#include <winsock2.h>
#include <ws2tcpip.h>

#include "code_trans.h"
#include "print.h"
#include "thread_pool.h"
#include "nlohmann/json_fwd.hpp"
#include "nlohmann/json.hpp"
#include "udp_receiver.h"

import utils;
import config;

int main(int argc, char** argv)
{
	init_config(argc, argv);

	udp_receiver::socket_create_parameters parameters;
	parameters.group = true;
	parameters.group_addr = get_config().udp_reply_parameters.group_addr;
	parameters.listen_port = get_config().udp_reply_parameters.send_port;
	parameters.listen_ip = "0.0.0.0";

	udp_receiver receiver(parameters);

	while (true)
	{
		auto messages = receiver.get_all_message();
		for(const auto& message: messages)
		{
			println("from {}, say: \"{}\", {} bytes"
				, inet_ntoa(message.message_address.sin_addr)
				, std::string_view{message.message_data.begin(), message.message_data.end()}
				, message.message_data.size()
			);
		}
	}
}